package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import dao.ArticleDAO;
import dao.ContentDAO;
import dao.ThemeDAO;
import dao.UserDAO;
import entity.Article;
import entity.Content;
import entity.Theme;
import entity.User;

/**
 * Servlet implementation class GetContentServlet
 */
@WebServlet("/GetContentServlet")
public class GetContentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private static ContentDAO contentDAO = ContentDAO.getInstance();
	private static ArticleDAO articledao = ArticleDAO.getInstance();
	private static ThemeDAO themedao = ThemeDAO.getInstance();
	private static UserDAO userdao = UserDAO.getInstance();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetContentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int article_id =Integer.parseInt(request.getParameter("article_id"));
		System.out.println("article_id"+article_id);
		Content content =  (Content) contentDAO.get(article_id);
		Article article = articledao.get(article_id);
		Theme theme = themedao.get(article.getTheme_id());
		User user = userdao.get(article.getUser_id());
	   String con = content.getContent();
		System.out.println("content:"+con);
		request.setAttribute("content", content);
		request.setAttribute("article", article);
		request.setAttribute("theme", theme);
		request.setAttribute("user", user);
		request.getRequestDispatcher("ArticleEditor.jsp").forward(request, response);
	}

	
}
